﻿//***********************开发者:赵祥   最后修订时间:2013年5月3日********************************************
//刷新验证码
function RefreshIdentifying() {
    var RandomValue = Mtopt.Random.Number.Next(0, 1000);
    $MEM("Identifying").src = "../../../../Service/Basic/GetIdentifyingCode.ashx?Random=" + RandomValue;
}
//载入系统时候载入
$MET.Load.Install(function () {
    //如果账户存在载入账户
    $MEM("LblQuestion").onclick = function () {
        var Uid = $MEM("TxtUid");
        var DivMessage = $MEM("DivMessage");
        if (Uid.value == "") {
            DivMessage.innerHTML = "<label>请输入账户</label>";
            return;
        }
        else {
            //载入问题
            var RTUrl = "../../../../Service/Basic/User/GetInfo.ashx";
            var RTData = "UserName=" + Uid.value;
            $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
                var Json = $MJO.GetObject(xmlData);
                //如果验证成功
                if (Json != null && Json.Successful == true) {
                    $MEM("LblQuestion").innerHTML = Json.Data.Question;
                    $MEM("LblQuestion").title = "提示：" + Json.Data.AnswerTip;
                }
            });
        }
    }
    //登录用户
    $MEM("BtnModity").onclick = function () {
        //读取控件
        var Uid = $MEM("TxtUid");
        var Answer = $MEM("TxtAnswer");
        var NewPwd = $MEM("TxtNewPwd");
        var ConInput = $MEM("TxtConInput");
        var Identifying = $MEM("TxtIdentifying");
        var DivMessage = $MEM("DivMessage");

        if (Uid.value == "") {
            DivMessage.innerHTML = "<label>请输入账户</label>";
            return;
        }
        if (Answer.value == "") {
            DivMessage.innerHTML = "<label>请输入答案</label>";
            return;
        }
        if (NewPwd.value == "") {
            DivMessage.innerHTML = "<label>请输入新密码</label>";
            return;
        }
        if (ConInput.value == "") {
            DivMessage.innerHTML = "<label>请再输一次新密码</label>";
            return;
        }
        if (ConInput.value != NewPwd.value) {
            DivMessage.innerHTML = "<label>两次密码不一致</label>";
            return;
        }
        if (Identifying.value == "") {
            DivMessage.innerHTML = "<label>请输入验证码</label>";
            return;
        }

        var RTUrl = "../../../../Service/Basic/ChekIdentifyingCode.ashx";
        var RTData = "Code=" + Identifying.value;
        //请求验证
        $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
            var Json = $MJO.GetObject(xmlData);
            //如果验证成功
            if (Json != null && Json.Successful == true) {
                //修改密码
                RTUrl = "../../../../Service/Basic/User/ModityPwd/OfAnswer.ashx";
                RTData = "UserName=" + Uid.value;
                RTData += "&Answer=" + Answer.value;
                RTData += "&NewPwd=" + NewPwd.value;
                //请求修改密码
                $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
                    var Json = $MJO.GetObject(xmlData);
                    if (Json != null && Json.Successful == true) {
                        DivMessage.innerHTML = "<label style='color:green;'>修改密码成功</label>";
                    }
                    else {
                        DivMessage.innerHTML = "<label style='color:red;'>" + Json.DivMessage + "</label>";
                    }
                });
            }
            else {
                DivMessage.innerHTML = "<label>" + Json.DivMessage + "</label>";
            }
            //清空信息
            Identifying.value = "";
            //刷新验证码
            RefreshIdentifying();
        });
    }
    //清空
    $MEM("BtnClear").onclick = function () {
        $MEM("TxtUid").value = "";
        $MEM("TxtAnswer").value = "";
        $MEM("TxtNewPwd").value = "";
        $MEM("TxtConInput").value = "";
        $MEM("TxtIdentifying").value = "";
        $MEM("DivMessage").innerHTML = "";
    }

    //回车事件触发
    $MEM("DivWindow").onkeydown = function (event) {
        var e = event || DivWindow.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == Mtopt.Keys.Enter) {
            $MEM("BtnModity").onclick();
        }
    }
    //刷新验证码
    RefreshIdentifying();
});